﻿// /*************************************************************************
//  *
//  *  Copyright (C) 2010 - 2011 Sonar Team
//  *
//  *  This program is free software: you can redistribute it and/or modify
//  *  it under the terms of the GNU General Public License as published by
//  *  the Free Software Foundation, either version 3 of the License, or
//  *  (at your option) any later version.
//  *
//  *  This program is distributed in the hope that it will be useful,
//  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  *  GNU General Public License for more details.
//  *
//  *  You should have received a copy of the GNU General Public License
//  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//  *
//  *************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MySql.Data.MySqlClient;

namespace NightWolf.Sonar
{
    public static class SonarProvider
    {
        public static SonardDatabase DbType = SonardDatabase.MYSQL;
        public static string Host { get; set; }
        public static string Username { get; set; }
        public static string Password { get; set; }
        public static string DB { get; set; }

        internal static MySqlConnection MYSQL_CONNECTION { get; set; }

        public static void Initialize(SonardDatabase dbtype, string host, string username, string password, string db)
        {
            DbType = dbtype;
            Host = host;
            Username = username;
            Password = password;
            DB = db;

            Connect();
        }

        public static void Connect()
        {
            switch (DbType)
            {
                case SonardDatabase.MYSQL:
                    MYSQL_CONNECTION = new MySqlConnection(string.Format("Server='{0}';Database='{1}';Uid='{2}';Pwd='{3}';", Host, DB, Username, Password));
                    MYSQL_CONNECTION.Open();
                    break;

                default:
                    throw new Exception("This dbtype is not supported yet !");
            }
        }
    }

    public enum SonardDatabase
    {
        MYSQL= 1,
        MSSQL = 2,
        SQLITE = 3,
        POSTGRESQL = 4,
        ORACLE = 5,
    }
}
